package com.mxpio.erp.common.workshop.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.jpa.model.Order;
import com.mxpio.erp.common.technology.entity.WorkCenter;
import com.mxpio.erp.common.technology.entity.WorkShop;
import com.mxpioframework.filestorage.entity.MxpioFileInfo;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "MB_ERP_WORKSHOP_OO")
@Schema(description="委外订单")
public class OutsourceOrder extends Order {

	private static final long serialVersionUID = 1L;

	@Column(name = "ORDER_TYPE_")
	@Schema(description = "单据类型")
	@Dict(dicCode="ERP_OO_ORDER_TYPE")
	private String orderType;

	@Schema(description = "加工商编号")
	@Column(name = "PN_CODE_")
	//@Dict(dicCode = "pnCode", dicEntity = Supply.class, dicText = "pnName")
	private String pnCode;

	@Schema(description = "加工商名称")
	@Column(name = "PN_NAME_")
	private String pnName;


	@Column(name = "PRODUCT_ITEM_CODE_")
	@Schema(description = "产品编号")
	private String productItemCode;
	
	@Column(name = "PRODUCT_ITEM_NAME_")
	@Schema(description = "产品名称")
	private String productItemName;
	
	@Column(name = "ITEM_SPEC_")
	@Schema(description = "规格型号")
	private String itemSpec;

	@Column(name = "PRODUCT_DRAWING_NO_")
	@Schema(description = "图号")
	private String productDrawingNo;

	@Column(name = "ORDER_QANTITY_")
	@Schema(description = "订单数量")
	private BigDecimal orderQuantity;
	
	@Column(name = "UNIT_CODE_")
    @Schema(description = "单位编号")
	@Dict(dicCode="ERP_TECH_UNIT_CODE")
    private String unitCode;

	@Column(name = "MAIN_WORKSHOP_")
	@Schema(description = "主制车间")
	@Dict(dicCode = "workShopCode",dicEntity = WorkShop.class,dicText = "workShopName")
	private String mainWorkshop;
	
	@Column(name = "WORK_CENTER_CODE_")
	@Schema(description = "工作中心")
	@Dict(dicCode = "workCenterCode",dicEntity = WorkCenter.class,dicText = "workCenterName")
	private String workCenterCode;

	/*	@Column(name = "PROCESS_ROUTE_")
	@Schema(description = "工艺路线")
	private String processRoute;*/


	@Column(name = "PLANNER_")
	@Schema(description = "计划员")
	private String planner;

	@Column(name = "BIZ_MAN_")
	@Schema(description = "业务员")
	@Dict(dicCode = "username",dicEntity = User.class,dicText = "nickname")
	private String bizMan ;

	@Column(name = "START_DATE_")
	@Schema(description = "计划开始日期")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date startDate;

	@Column(name = "END_DATE")
	@Schema(description = "计划完成日期")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date endDate;

	@Column(name = "REFERENCE_DATE_")
	@Schema(description = "参考日期")
	//@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date referenceDate;

	@Column(name = "ENTRUST_DEPT_")
	@Schema(description = "委托单位")
	private String entrustDept;

	@Column(name = "MEMO_")
	@Schema(description = "加工要求(备注)")
	private String memo;

	@Column(name = "MACHINING_DRAWING_")
	@Schema(description = "加工图纸")
	@Dict(dicCode = "fileNo", dicEntity = MxpioFileInfo.class, dicText = "fileName")
	private String machiningDrawing;

	@Column(name = "ACTUAL_BEGIN_DATE")
	@Schema(description = "实际开工日期")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date actualBeginDate;

	@Column(name = "ACTUAL_FINISH_DATE")
	@Schema(description = "实际完工日期")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date actualFinishDate;

/*	@Column(name = "ORDER_CLASS_")
	@Schema(description = "单据分类")
	@Dict(dicCode="ERP_WORKSHOP_ORDER_CLASS")//正常1/返工2
	private String orderClass;*/

	@Column(name = "TAX_RATE_")
	@Schema(description = "税率")
	private BigDecimal taxRate ;

	@Column(name = "TAX_PRICE_")
	@Schema(description = "含税单价")
	private BigDecimal taxPrice;

	@Column(name = "UNTAX_PRICE_")
	@Schema(description = "无税单价")
	private BigDecimal untaxPrice;

	@Column(name = "UNTAX_AMOUNT_")
	@Schema(description = "无税金额")
	private BigDecimal untaxAmount;

	@Column(name = "TAX_")
	@Schema(description = "税额")
	private BigDecimal tax;

	@Column(name = "TOTAL_AMOUNT")
	@Schema(description = "价税合计")
	private BigDecimal totalAmount;

	@Transient
	private List<OutsourceOrderItem> outsourceOrderItems;

	@Override
	public String initTypeCode() {
		return "PU1";
	}
}
